package com.linchong.concurrency.chapter3;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author:linchong
 * @CreateTime:2020-01-01 21:50
 * @Description:
 */
@Slf4j
public class CreateThread1 {

	public static void main(String[] args) {
		Thread t1 = new Thread();
		Thread t2 = new Thread() {
			@Override
			public void run() {
				log.info("===");
			}
		};
		//run：本线程启动，start:main调用，新产生一个
		//新建时，调用init方法，方法参数：
		// 线程组，类似于策略模式执行的接口，线程的名字，栈大小，jvm权限相关
		// init(ThreadGroup g, Runnable target,
		// String name,long stackSize，AccessControlContext acc,)
		//name:"Thread-" + nextThreadNum(),nextThreadNum是sync修饰的静态的方法
		t1.start();
		t2.start();
		log.info("name:{}", t1.getName());
		log.info("name:{}", t2.getName());

		/**
		 * 构造函数1：Thread()
		 * 创建线程对象Thread，默认有一个线程名，以Thread-开头，从0开始计数*/
		/*init(ThreadGroup g, Runnable target, String name,long stackSize) */

		/**
		 * 构造函数2：Thread(Runnable target)
		 * 如果构造Thread中没有传递Runnable或者没有覆写Thread的run方法，该Thread将不会调用任何东西
		 * 如果传递了Runnable接口的实例或者覆写了Thread的run方法，则会执行该方法的逻辑单元(即逻辑代码)
		 *
		 *
		 * 构造函数3：Thread(String name)
		 *
		 * 构造函数4：Thread(ThreadGroup group,Runnable target,String name)
		 *
		 * 构造函数5：Thread(ThreadGroup group,Runnable target,String name,long stackSize)
		 *
		 * 构造函数6：Thread(ThreadGroup group,String name)
		 */

		//Thread()
		//Thread(Runnable target)
		//Thread(Runnable target,String name)
		//Thread(String name)
		Thread t3 = new Thread("MyName");
		Thread t4 = new Thread(() -> {
			log.info("it is a runnable...");
		});

		log.info("t3 name:{}", t3.getName());

		log.info("t4 name:{}", t4.getName());

		Thread t5 = new Thread(() -> {
			log.info("Runnable...");
		}, "RunnableThread");
		t5.start();

		/**
		 * 如果构造线程对象时没有传入ThreadGroup,Thread会默认获取父线程的ThreadGroup作为该线程的
		 * ThreadGroup,此时子线程和父线程会在同一个threadGroup中
		 */

	}
}
